<!--<style>-->
<!--    th{-->
<!--        font-weight: bold;-->
<!--    }-->
<!--    th,td{-->
<!--        text-align: center;-->
<!--    }-->
<!--    thead,tr{-->
<!--        border-bottom: 1px dashed #ddd;-->
<!--        line-height: 40px;-->
<!--    }-->
<!---->
<!--    .box{-->
<!--        padding: 10px;-->
<!--    }-->
<!---->
<!--</style>-->
<?php
    $proxy = Model()->table('proxy')->where(['member_id' => $minfo['member_id']])->find();

    if (count($_POST)) {
        do {

            $info = Model()->table('proxy_apply')->where(['member_id' => $minfo['member_id']])->limit(1)->find();
//            if ($_SESSION['mobile_code']['mobile'] != $_POST['contact'] || $_SESSION['code'] != $_POST['captcha']) {
//            ?>
<!--                <script>-->
<!--                    layer.msg("验证码错误");-->
<!--                </script>-->
<!--            --><?php
//                break;
//            }
//            else{
//                $_SESSION['mobile_code'] = null;
//            }
            $data = array(
                'member_id' => $minfo['member_id'],
                'name'      => $_POST['name'],
                'contact'   => $_POST['contact'],
                'time'      => time(),
                'msg'       => $_POST['msg'],
                'idcard'    => $_POST['idcard']
            );
            if ($proxy && $proxy['is_buyer'] == 1) {
                $data['proxy_member_id'] = $proxy['parent_id'];
            } else {
                $data['proxy_member_id'] = 0;
            }
            if ($info) {
                $data['id'] = $info['id'];
            }
            $success = Model()->table('proxy_apply')->insert($data, true);
            if ($success) {
                ; ?>
                <script>
                    layer.msg("提交成功");
                </script>
                <?php
            }
            ?>

            <?php
        } while (0);
    }
?>
<link rel="stylesheet" href="/packages/resource/pintuer/pintuer.css">
<script src="/data/resource/js/jquery.js"></script>
<script src="/packages/resource/pintuer/pintuer.js"></script>
<div class="pintuer">
    <?php
        $info = Model()->table('proxy_apply')->where(['member_id' => $minfo['member_id']])->order('id desc')->limit(1)->find();
        if (!$info) {
            $info = array();
        }

        if ($info['status'] == 'state_cancel') {
            ?>
            <div class="alert alert-red">
                您的申请已经被拒绝，请填写信息重试
            </div>
            <?php
        } else if (isset($info['status'])) {
            ?>
            <div class="alert alert-blue text-center">
                审核中，请耐心等待
            </div>
            <?php
        }
    ?>
    <form action="/wap/tmpl/member/distribute_center.php?action=apply" method="post" class="padding ">
        <div class="from-group padding-bottom">
            <div class="label">
                姓名：
            </div>
            <div class="field">
                <input type="text" class="input" name='name' value='<?php echo $info['name'] ?>'
                       data-validate="required:姓名不能为空"
                >
            </div>
        </div>

        <div class="form-group">
            <div class="label">
                身份证号：
            </div>
            <div class="field">
                <input type="text" class="input" name="idcard" value="<?php echo $info['idcard'] ?>"
                       data-validate="required:身份证号码不能为空,regexp#^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$:身份证号码格式不对"
                >
            </div>
        </div>
<!--        <div class="form-group">-->
<!--            <div class="label">-->
<!--                手机号：-->
<!--            </div>-->
<!--            <div class="field">-->
<!--                <div class="input-group">-->
<!--                    <input type="text" class="input" name="contact" value="--><?php //echo $info['contact'] ?><!--"-->
<!--                           data-validate="required:手机号码不能为空,tel:手机号码格式错误"-->
<!--                    >-->
<!--                    <span class="addon" id="send_captcha">-->
<!--                        发送验证码-->
<!--                        <span id="countdown">-->
<!---->
<!--                        </span>-->
<!--                    </span>-->
<!--                </div>-->
<!---->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="form-group">-->
<!--            <div class="label">-->
<!--                验证码：-->
<!--            </div>-->
<!--            <div class="field">-->
<!--                <input type="text" class="input" name="captcha" value=""-->
<!--                       data-validate="required:验证码不能为空"-->
<!--                >-->
<!--            </div>-->
<!--        </div>-->
        <div class="form-group">
            <div class="label">
                留言：
            </div>
            <div class="field">
                <textarea type="text" class="input" name="msg"
                          data-validate="required:留言内容不能为空"
                ><?php echo $info['msg'] ?></textarea>
            </div>
        </div>

        <div class="margin-big-top text-center">
            <button class="button bg-yellow" type="submit">提交申请</button>
        </div>
    </form>
</div>

<script>
    var timer = null;
    $('#send_captcha').click(function () {
        if (timer != null) {
            return;
        }

        var mobile = $('[name=contact]').val();
        if (!/^1[34578][0-9]{9}$/.test(mobile.trim())) {
            layer.msg("请填写正确的手机号");
            return false;
        }

        $.get('/shop/?act=seccode&op=mobile_send_message&mobile=' + mobile, function (msg) {
            console.log(msg);
            if (msg == 0) {
                layer.msg("发送成功");
                var cd = $('#countdown')[0];
                cd.innerHTML = 60;
                timer = setInterval(function () {
                    cd.innerHTML--;
                    if (parseInt(cd.innerHTML) == 0) {
                        clearInterval(timer);
                        timer = null;
                        cd.innerHTML = '';
                    }
                }, 1000);
            }
            else {
                layer.msg("发送失败");
            }
        });


    });

</script>


